package cloud.shyidong.core.util;

import cn.hutool.core.io.FileUtil;

import java.io.File;

/**
 * @Description TODO
 * @Author syd
 * @Date 2022/12/6
 */
public final class FileUtils {
    
    public static final String TEMP = "temp";
    
    public static void templateFileCopy(String templateDir, String fileName) {
        templateFileCopy(templateDir, fileName, false);
    }
    
    public static void templateFileCopy(String templateDir, String fileName, boolean update) {
        if (update) {
            File tempFile = new File(templateDir + TEMP + File.separator + fileName);
            if (tempFile.exists()) {
                File templatePath = new File(templateDir);
                FileUtil.copy(tempFile, templatePath, true);
                tempFile.delete();
            }
        } else {
            File tempFile = new File(templateDir + TEMP + File.separator + fileName);
            File templatePath = new File(templateDir);
            FileUtil.copy(tempFile, templatePath, true);
            tempFile.delete();
        }
    }
    
}
